#include <bits/stdc++.h>

using namespace std;

int r,c,a[111][111],maxa;
int xx[] = {-1,1,0,0};
int yy[] = {0,0,1,-1};
void dfs(int x,int y,int s){
    if(s>maxa)maxa=s;
    for(int i=0;i<4;i++){
        int dx = xx[i]+x;
        int dy = yy[i]+y;
        if(dx>=1&&dx<=r&&dy>=1&&dy<=c&&a[dx][dy]<a[x][y]){
            dfs(dx,dy,s+1);
        }
    }
    return;
}
int main()
{
    cin>>r>>c;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            dfs(i,j,1);
        }
    }
    cout<<maxa;
    return 0;
}
